package com.douqu.game.activity.entity.camp;

import com.douqu.game.activity.GameServer;
import com.douqu.game.activity.entity.MainServerInfo;
import com.douqu.game.core.e.E_BattleDetailType;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LogUtils;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-01-22 20:32
 */
public class StartCampBattleParam
{
    private String battleId;

    private int battleType;

    private int battleDetailType;

    private MatchTempObject player;

    private MatchTempObject target;

    private String battleServerHost;

    private int battleServerPort;

    private long createTime;

    public StartCampBattleParam()
    {

    }


    public StartCampBattleParam(String battleId, int battleType, int battleDetailType, MatchTempObject player, MatchTempObject target, String battleServerHost, int battleServerPort)
    {
        this.battleId = battleId;
        this.battleType = battleType;
        this.battleDetailType = battleDetailType;
        this.player = player;
        this.target = target;
        this.battleServerHost = battleServerHost;
        this.battleServerPort = battleServerPort;
        this.createTime = DataFactory.currentTime;
    }

    public void sendStartBattle()
    {
        MainServerInfo mainServerInfo1 = GameServer.getInstance().getMainServerInfo(player.getBaseInfo().getServerId());
        if(mainServerInfo1 == null)
        {
            LogUtils.error("玩家所在的服务器已经关闭或者不存在,请检查 -> " + player.getBaseInfo().getServerId());
            return;
        }

        if(battleDetailType == E_BattleDetailType.PVP_SPAN_CAMP.getCode())
        {
            MainServerInfo mainServerInfo2 = GameServer.getInstance().getMainServerInfo(target.getBaseInfo().getServerId());
            if(mainServerInfo2 == null)
            {
                LogUtils.error("玩家所在的服务器已经关闭或者不存在,请检查 -> " + target.getBaseInfo().getServerId());
                return;
            }

            LogUtils.warn(mainServerInfo1 + " -> 通知玩家的主服去连接战斗服 -> " + battleServerHost + ":" + battleServerPort + "," + player.getBaseInfo().getName() + ",battleId:" + battleId);
            LogUtils.warn(mainServerInfo2 + " -> 通知玩家的主服去连接战斗服 -> " + battleServerHost + ":" + battleServerPort + "," + target.getBaseInfo().getName() + ",battleId:" + battleId);
            mainServerInfo1.sendStartBattle(battleId, battleType, battleDetailType, player.getBaseInfo().getObjectIndex(), target.getBaseInfo(), battleServerHost, battleServerPort);
            mainServerInfo2.sendStartBattle(battleId, battleType, battleDetailType, target.getBaseInfo().getObjectIndex(), player.getBaseInfo(), battleServerHost, battleServerPort);
        }
        else
        {
            LogUtils.warn(mainServerInfo1 + " -> 通知玩家的主服去连接战斗服 -> " + battleServerHost + ":" + battleServerPort + "," + player.getBaseInfo().getName() + ",battleId:" + battleId);
            mainServerInfo1.sendStartBattle(battleId, battleType, battleDetailType, player.getBaseInfo().getObjectIndex(), target.getBaseInfo(), battleServerHost, battleServerPort);
        }
    }

    public boolean isOverdue()
    {
        return DataFactory.currentTime - createTime >= 60000;
    }

    public String getBattleId() {
        return battleId;
    }

    public void setBattleId(String battleId) {
        this.battleId = battleId;
    }


    public String getBattleServerHost() {
        return battleServerHost;
    }

    public void setBattleServerHost(String battleServerHost) {
        this.battleServerHost = battleServerHost;
    }

    public int getBattleServerPort() {
        return battleServerPort;
    }

    public void setBattleServerPort(int battleServerPort) {
        this.battleServerPort = battleServerPort;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }


    @Override
    public String toString() {
        return "{" +
                "battleId='" + battleId + '\'' +
                ", battleType=" + battleType +
                ", battleDetailType=" + battleDetailType +
                ", player=" + player +
                ", target=" + target +
                ", battleServerHost='" + battleServerHost + '\'' +
                ", battleServerPort=" + battleServerPort +
                '}';
    }
}
